package com.zjc.app.api.sdk.client;

import com.google.gson.reflect.TypeToken;
import com.zjc.app.api.sdk.dto.ResultDto;
import com.zjc.app.api.sdk.dto.request.ApiSearchTowerReqDTO;
import com.zjc.app.api.sdk.dto.result.ApiCommandResultDTO;
import com.zjc.app.api.sdk.dto.result.ApiSearchTowerResultDTO;
import com.zjc.app.api.sdk.exception.AppBizRuntimeException;

import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;

/**
 * 指令客户端
 */
public class CommandClient extends BaseClient {

    public CommandClient(String serverUrl, String appId, String appSecret, Integer connectTimeout, Integer readTimeout) {
        super(serverUrl, appId, appSecret, connectTimeout, readTimeout);
    }

    /**
     * 塔机一键询塔指令下发
     * @param request
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<ApiSearchTowerResultDTO> searchTower(ApiSearchTowerReqDTO request) throws IOException, AppBizRuntimeException {
        String url = "/v1/command/tower.search";
        return super.doPost(url, request, new TypeToken<ResultDto<ApiSearchTowerResultDTO>>() {});
    }

    /**
     * 查询指令结果
     * @param resultId 指令结果ID
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<ApiCommandResultDTO> commandResult(String resultId) throws IOException, AppBizRuntimeException {
        String url = "/v1/command/result";
        Map<String, String> params = new TreeMap<>();
        params.put("resultId", resultId);
        return super.doGet(url, params, new TypeToken<ResultDto<ApiCommandResultDTO>>() {});
    }
}
